Ext.namespace("Meeting");
Meeting.List = function() {
		this.mtName = new Ext.form.TextField({
			fieldLabel: '工作名称',
			blankText: '请填写工作名称'
		});
		this.mtStartDate=new Ext.form.DateField({	
			fieldLabel: '开始日期',
			emptyText: '请选择',
			format:'Y-m-d',
			disabledDays:[0-6]
		});
		this.mtEndDate=new Ext.form.DateField({
			fieldLabel: '结束日期',
			emptyText: '请选择',
			format:'Y-m-d',
			disabledDays:[0-6]
		});
		this.mtCreator = new Ext.form.TextField({
			fieldLabel: '发起人',
			blankText: '请填写发起人'
		});
		this.form=new Ext.form.FormPanel({	
			title:'工作列表',
			width:1000,			
			frame:true,						
            items: [{
	            layout:'column',
	            labelAlign: 'right',
	            items: [{	
	                columnWidth:.25,
	                layout: 'form',
	                items:[this.mtName]
		            },{
		                columnWidth:.31,
		                layout: 'form',
		                items:[this.mtCreator]
		            },{
		                columnWidth:.22,
		                layout: 'form',
		                items:[this.mtStartDate]
		            },{
		                columnWidth:.22,
		                layout: 'form',
		                items:[this.mtEndDate]
	            }]
        	}],
	        buttons: [{
	            text: '查找工作',
	            iconCls: 'icon-search',
	            scope:this,
	            handler: this.searchMeeting	            
	        }, {
	            text: '添加工作',
	            iconCls: 'icon-add',
	            handler: this.addMeeting
	        }]
		});	
		Meeting.List.superclass.constructor.call(this,{
	        resizable: false,
	        frame:false,
	        items: [this.form]
		});	
};

Ext.extend(Meeting.List, Ext.Viewport, {
	searchMeeting:function(){
		var conn = new Ext.data.Connection({
				url: '../meeting/searchMeeting.form?timesnap='+Date.parse(new Date()),
			method: 'POST'
		})
		var mtStartDate = this.mtStartDate.getValue()?this.mtStartDate.getValue().format('Y-m-d'):'';
		var mtEndDate = this.mtEndDate.getValue()?this.mtEndDate.getValue().format('Y-m-d'):'';
		var calType ="month";
		var y;
		var m;
		var d;
		if(mtStartDate&&mtEndDate){
			var days =(Date.parseDate(mtEndDate,"Y-m-d").getTime()-Date.parseDate(mtStartDate,"Y-m-d").getTime())/(1000*60*60*24);
			if(days>7){
			   	y = mtStartDate.substring(0,4);
				m= parseInt(mtStartDate.substring(5,7))-1;
				calType ="month"
			}else if(days>=1&&days<=7){
			     y = mtStartDate.substring(0,4);
				 m= parseInt(mtStartDate.substring(5,7))-1;
				 d= parseInt(mtStartDate.substring(8,10));
				calType="agendaWeek"
			}else{
				 y = mtStartDate.substring(0,4);
				 m= parseInt(mtStartDate.substring(5,7))-1;
				 d= parseInt(mtStartDate.substring(8,10));
				calType="agendaDay";
			}
		}else if(mtStartDate){
			y = mtStartDate.substring(0,4);
			m= parseInt(mtStartDate.substring(5,7))-1;
		}else{
			y = mtEndDate.substring(0,4);
			m= parseInt(mtEndDate.substring(5,7))-1;
		}
		Utils.request(conn,{
			params: {
				mtName:this.mtName.getValue(),
				mtStartDate: mtStartDate,
				mtEndDate: mtEndDate,
				mtCreator:this.mtCreator.getValue()
			},
			scope:this,
			y:y,
			m:m,
			d:d,
			calType:calType,
			success:function(data){
			   this.array =[];
			   for(var i=0;i<data.result.length;i++){
				   var obj={};
				   obj.start=Date.parseDate(data.result[i].MT_START_DATE,'Y-m-d H:i');
				   obj.end=Date.parseDate(data.result[i].MT_END_DATE,'Y-m-d H:i');
				   obj.title=data.result[i].MT_NAME;
				   obj.allDay=false;
				   obj.MT_ID = data.result[i].MT_ID;		
				   obj.dbClick= "dbcilck";
				   this.array.push(obj);
				 }
				 if(this.y)
				 	var y = this.y
				 if(this.m)
				 	var m =this.m
				 if(this.d)
				 	var d = this.d
				 $('#calendar').empty();
				 $('#calendar').fullCalendar({
					theme: true,
					header: {
						left: 'prev,next today',
						center: 'title',
						right: 'month,agendaWeek,agendaDay'
					},
					year:y,
					month:m,
					date:d,
					defaultView:this.calType,
					editable: false,
					events: this.array
				});
			}
		});
	},
	searchMeetingToday:function(){
		Meeting.Today.instance = new Meeting.Today();
		Meeting.Today.instance.show();
	},
	addMeeting:function(){
		Meeting.Arrange.instance = new Meeting.Arrange();
		Meeting.Arrange.instance.show();
	}
});
function dbclickFn(MT_ID){
		conn = new Ext.data.Connection({
			url: '../meeting/searchMeetingById.form?timesnap='+Date.parse(new Date()),
			method: 'POST'
		});
		Utils.request(conn,{
			params: {
				mtId:MT_ID
			},
			scope:this,
			success:function(data){
				Meeting.Add.instance = new Meeting.Add();
				Meeting.Add.instance.initEdit(data.result);
				Meeting.Add.instance.show();
			}
		});
	};
Ext.onReady(function() {
	 var flag="";
		 //访问action
	 var conn = new Ext.data.Connection({
	    url:'../security/checkMenu.form?timesnap=' + Date.parse(new Date()),
	    method:'post'
	 });
	 var param={menuName:"rb"};
	  //alert(Ext.util.JSON.encode(param));  
		 Utils.request(conn,{
		    params:param,
		    scope:this,
		    success:function(data){
		     if(data.access=="true"){
		      flag="true"
				    Ext.QuickTips.init();
				    Ext.BLANK_IMAGE_URL = '../resources/images/default/s.gif';
				   	Meeting.List.instance = new Meeting.List();   
				   	Meeting.List.instance.show();
				   	Meeting.List.instance.searchMeeting();
			}else{
	      flag="false"
	      alert("没有权限");
	      return;
	     }
	    }
	  });
});